(ns com.yawmark.euler.clj.e43
    (:use [clojure.contrib.combinatorics :only (permutations)]))

(defn pandigitals []
  (permutations "0123456789"))

(defn as-int [coll]
  (Integer/parseInt (apply str coll)))

(defn groups [digit-string]
  (map as-int (partition 3 1 (rest digit-string))))

(defn divisible? [dividend divisor]
  (zero? (mod dividend divisor)))

(defn has-the-mojo? [digits]
  (every?
    true?
    (map #(divisible? %1 %2) (groups digits) [2 3 5 7 11 13 17])))

(defn euler-43 []
  (reduce +
          (map
            #(BigInteger. (apply str %))
            (filter has-the-mojo? (pandigitals)))))



